﻿using System.Web;

namespace StreetPacMan.FrontEnd.Infra
{
    public static class JsonPSerializer
    {
        public static string GetResponse(HttpContext context, object results)
        {
            var jsonObjectResponse = JsonSerializer.SerializeToString(results);

            var prefix = context.Request.QueryString["jsoncallback"];
            string response;
            if (string.IsNullOrEmpty(prefix))
            {
                response = jsonObjectResponse;
            }
            else
            {
                response = prefix + " ( " + jsonObjectResponse + " );";
            }
            return response;         
        }
    }
    internal static class StringExtensions
    {
        public static string AsPascalCase(this string source)
        {
            return char.IsUpper(source[0]) ? source : char.ToUpper(source[0]) + source.Substring(1);
        }
    }
}